package com.bee.beemanage.system.common.utils.context;

import com.bee.beemanage.api.entity.SysUser;
import lombok.Data;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * 获取当前操作的用户
 */
@Data
public class CurrentUser {

    /**
     * 用户ID
     **/
    public static String getUserId()
    {
        return getLoginUser().getId();
    }


    /**
     * 获取用户账户
     **/
    public static String getUsername()
    {
        return getLoginUser().getUsername();
    }

    /**
     * 获取用户
     **/
    public static SysUser getLoginUser()
    {
        return (SysUser) getAuthentication().getPrincipal();
    }

    /**
     * 获取Authentication
     */
    public static Authentication getAuthentication()
    {
        return SecurityContextHolder.getContext().getAuthentication();
    }
}
